﻿// --------------------------------
// <copyright file="IntrinsicElement.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System.Configuration;

namespace Tronsoft.Actucal.CalculationEngineCreator.ScriptConfiguration
{
    /// <summary>
    /// This class represents the script element in the application's configuration file. see the example. 
    /// 
    /// Example:
    ///   <scriptGeneration>
    ///     <IntrinsicObject name="test1" sourceDirectory="c:\temp\input" processedDirectory="c:\temp\processed">
    ///         <scripts>
    ///             <clear/>
    ///             <add name="testScript1.txt" outputDirectory="c:\temp\output" template="c:\temp\script\template1.txt"  type="Tronsoft.Actucal.CalculationEngineCreator.FileNameReplacerProcessor, Tronsoft.Actucal.CalculationEngineCreator" />
    ///             <add name="testScript2.txt" outputDirectory="c:\temp\output" template="c:\temp\script\template2.txt" type="Tronsoft.Actucal.CalculationEngineCreator.FileNameReplacerProcessor, Tronsoft.Actucal.CalculationEngineCreator" />
    ///         </scripts>
    ///     </IntrinsicObject>
    ///    </scriptGeneration>
    /// 
    /// </summary>
    public class IntrinsicElement : ConfigurationElement
    {
        private const string NAME_ATTRIBUTE = "name";
        private const string CLASS_ATTRIBUTE = "class";
        private const string ASSEMBLY_ATTRIBUTE = "assembly";

        public IntrinsicElement()
        {

        }

        public IntrinsicElement(string name, string type, string asm)
        {
            this.Name = name;
            this.Class = type;
            this.Assembly = asm;
        }

        /// <summary>
        /// The name attribute of the IntrinsicObject element. The following characters are 
        /// not allowed: ~!@#$%^&*()[]{}/;'\"|\\
        /// </summary>
        [ConfigurationProperty(NAME_ATTRIBUTE, IsRequired = true, IsKey = true)]
        [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\")]
        public string Name
        {
            get { return base[NAME_ATTRIBUTE] as string; }
            set { base[NAME_ATTRIBUTE] = value; }
        }

        /// <summary>
        /// The type attribute that is a child of the IntrinsicObject element. Get the 
        /// type of the intrinsic object class.
        /// </summary>
        /// <remarks>
        /// The fully qualified namespace and class name for the type of provider configured by this <see cref="ScriptElement"/> instance. 
        /// </remarks>
        [ConfigurationProperty(CLASS_ATTRIBUTE, IsRequired = true)]
        public string Class
        {
            get { return base[CLASS_ATTRIBUTE] as string; }
            set { base[CLASS_ATTRIBUTE] = value; }
        }

        /// <summary>
        /// The assembly attribute that is a child of the IntrinsicObject element. Gets or 
        /// sets the type of the template processor configured by this class. 
        /// </summary>
        /// <remarks>
        /// The fully qualified namespace and class name for the type of provider configured by this <see cref="ScriptElement"/> instance. 
        /// </remarks>
        [ConfigurationProperty(ASSEMBLY_ATTRIBUTE, IsRequired = true)]
        public string Assembly
        {
            get { return base[ASSEMBLY_ATTRIBUTE] as string; }
            set { base[ASSEMBLY_ATTRIBUTE] = value; }
        }
    }
}
